package com.cw.java8.lambda;

import com.cw.java8.functionInterface.MyPrint;

/**
 * Lambda表达式有参数演示
 */
public class LambdasHasParameter {

    public static void main(String[] args) {

        //1.使用Lambda表达式实现带有方法参数的对象
        MyPrint myPrint = (String msg) -> {
            System.out.println("打印：" + msg);
        };
        myPrint.print("Java");

        //2.可以省略参数的类型，编译器会自动匹配
        MyPrint myPrint2 = (msg) -> {
            System.out.println("打印2：" + msg);
        };
        myPrint2.print("C++");

        //3.如果只有一个参数，也可以省略括号
        MyPrint myPrint3 = msg -> {
            System.out.println("打印3：" + msg);
        };
        myPrint3.print("Golang");

        //4.如果方法块只有一句代码，也可以省略花括号
        MyPrint myPrint4 = msg -> System.out.println("打印4：" + msg);
        myPrint4.print("Python");
    }
}
